package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.core.pojo.entity.IntegralGrade;
import com.atguigu.srb.core.service.IntegralGradeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 积分等级表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-10-11
 */
@RestController
@RequestMapping("/api/core/integralGrade")
@Api(tags = "积分等级用户模块")
public class ApiIntegralGradeController {

    @Autowired
    IntegralGradeService integralGradeService;

    @ApiOperation("查询所有的积分等级")
    @GetMapping
    public List<IntegralGrade> list(){
        return integralGradeService.list();
    }

    @ApiOperation("根据id查询积分等级")
    @GetMapping("{id}")
    public IntegralGrade getById(@PathVariable("id") Long id){
        return integralGradeService.getById(id);
    }

    @ApiOperation("查询会员的借款额度")
    @GetMapping("borrowAmount")
    public ResponseVo borrowAmount(@RequestHeader(value = "token",required = false)
                                       String token){
        BigDecimal amount = integralGradeService.getBorrowAmountByUserId(token);
        return ResponseVo.ok().data("amount",amount);
    }
}

